package interfaces.menu;

import java.util.Collection;

import main.InitGame;

import org.fenggui.binding.render.ImageFont;
import org.fenggui.event.ButtonPressedEvent;
import org.fenggui.event.IButtonPressedListener;
import org.fenggui.layout.StaticLayout;

import fileHandling.language.LanguageLoader;
import fileHandling.language.interfaces.MenuText;
import interfaces.GUISource;
import interfaces.WordWrapHelper;
import interfaces.language.LanguageButton;
import interfaces.language.LanguageWindow;
import interfaces.superWidgets.InterfaceLabel;

public class LeaveGameWindow extends LanguageWindow {
	
	public LeaveGameWindow(AbsMenu menu) {
		super(false, MenuText.Leave_Game);
		
		setSize(menu.getWidth() / 3, menu.getHeight() / 6);
		setXY((menu.getWidth() / 2) - (getWidth() / 2), (menu.getHeight() / 2) - (getHeight() / 2));
		
		content.setLayoutManager(new StaticLayout());
		layout();
		
		ImageFont font = GUISource.middleFont;
		
		InterfaceLabel l = new InterfaceLabel(font);
		l.setSize(content.getWidth(), font.getHeight());
		Collection<InterfaceLabel> labels = WordWrapHelper.getCentricLabels(l, LanguageLoader.get(MenuText.Really_Leave));
		int y = content.getHeight() - font.getHeight();
		for(InterfaceLabel label : labels) {
			label.setY(y);
			content.addWidget(label);
			y -= label.getHeight();
		}
		
		int buttonWidth = content.getWidth() / 2;
		int buttonHeight = font.getHeight() * 2;
		
		LanguageButton yesButton = new LanguageButton(MenuText.Yes, font);
		yesButton.setXY(0, 0);
		yesButton.setSize(buttonWidth, buttonHeight);
		yesButton.addButtonPressedListener(new IButtonPressedListener() {
			@Override
			public void buttonPressed(ButtonPressedEvent e) {
				InitGame.get().endCurrentGame();
				close();
			}
		});
		content.addWidget(yesButton);
		
		LanguageButton noButton = new LanguageButton(MenuText.No, font);
		noButton.setXY(yesButton.getWidth(), 0);
		noButton.setSize(buttonWidth, buttonHeight);
		noButton.addButtonPressedListener(new IButtonPressedListener() {
			@Override
			public void buttonPressed(ButtonPressedEvent e) {
				close();
			}
		});
		content.addWidget(noButton);
		
		layout();
	}
}